/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.command;

import controller.Controlador;
import javax.swing.JPanel;
import view.FabricaPaneles;
import view.InicialPanel;
import view.NavigationPanel;
import view.PrincipalGUI;

/**
 *
 * @author Pioli
 */
public class ChangePanelCommand implements Command{
    private PrincipalGUI principal;
    private JPanel currentPanel, titlePanel, nextPanel;
    private NavigationPanel navPanel;
    private Controlador currentController;
    private String titulo;
    
    public ChangePanelCommand (PrincipalGUI main, JPanel current, JPanel title, NavigationPanel nav){
        //informacion de referencia para cambiar el panel
        this.principal = main;
        this.currentPanel = current;
        this.titlePanel = title;
        this.navPanel = nav;
        
        //el siguiente panel es el inicial.
        this.nextPanel = new InicialPanel();
        
        //el siguiente panel no tiene titulo
        this.titulo = "";
        
    }
    public void setNextPanel(JPanel next){
        this.nextPanel = next;
    }
    
    public void setNextTitle(String title){
        this.titulo = title;
    }
    
    @Override
    public void execute() {
        principal._title.remove(titlePanel);
        principal._content.remove(currentPanel);
        principal._navigation.remove(navPanel);
        
        //setea nuevos paneles
        currentPanel = nextPanel;
        navPanel = FabricaPaneles.getNavigationPanel((int)currentPanel.getPreferredSize().getWidth());
        titlePanel = FabricaPaneles.getTitlePanel(titulo);
        
         //barra de titulo
        principal._title.add(titlePanel);
        
        //añade el paneñ principal
        principal._content.add(currentPanel);
        
        //barra de navegacion
        principal._navigation.add(navPanel);
                      
        //actualizo vista
        principal.validate();    ;
    }
    
}
